//
//  ILHomeViewController.m
//  ILife
//
//  Created by lanou on 15/10/29.
//  Copyright © 2015年 ILife. All rights reserved.
//

#import "ILHomeViewController.h"
#import "ILHomeTableViewCell.h"
#import "ILClearCachFile.h"
#import "ILHomeArticTableViewController.h"

#import "ILHomeCarCollectionTableViewController.h"

#import "ILFavoriteMusicListViewController.h"

#import "ILVideoTableViewController.h"

#import "ILAbouOurMessageViewController.h"
@interface ILHomeViewController ()<UITableViewDataSource,UITableViewDelegate>;

@property (nonatomic, strong) UITableView *mainTableView;
@property (nonatomic, strong) UIImageView *picImg;

@end

@implementation ILHomeViewController


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.mainTableView reloadData];
    

    
    UIImageView *headImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT/3)];
    
    headImg.image = [UIImage imageNamed:@"image"];
    
    _mainTableView.tableHeaderView = headImg;
    
    
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor clearColor];
    
    self.navigationItem.title = @"设置";

    _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:(UITableViewStylePlain)];
    
    [_mainTableView registerClass:[ILHomeTableViewCell class] forCellReuseIdentifier:@"cell"];
    

    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    _mainTableView.tableFooterView = [[UIView alloc]init];
    
    
    
    [self.view addSubview:_mainTableView];
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ILHomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

    if (indexPath.row == 0) {
        cell.titleLabel.text = @"视频收藏";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    else if (indexPath.row == 1)
    {
        cell.titleLabel.text = @"音乐收藏";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    else if (indexPath.row == 2)
    {
        cell.titleLabel.text = @"文章收藏";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    else if (indexPath.row == 3)
    {
        cell.titleLabel.text = @"汽车收藏";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    else if (indexPath.row == 4)
    {
        cell.titleLabel.text = @"清除缓存";
        ILClearCachFile *cach = [[ILClearCachFile alloc]init];
        cell.cachsLabel.text = [NSString stringWithFormat:@"%.2fM",[cach showCachs]];

    }else if(indexPath.row == 5)
    {
        cell.titleLabel.text = @"关于我们";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if (indexPath.row == 4) {
        ILClearCachFile *cachs = [[ILClearCachFile alloc]init];
        
        [cachs clearCachs];
        
        [self.mainTableView reloadData];
    }
    
    if (indexPath.row == 2) {
        ILHomeArticTableViewController *articVC = [[ILHomeArticTableViewController alloc]init];
        
        [self.navigationController pushViewController:articVC animated:YES];
    }
    

    if (indexPath.row == 3) {
        ILHomeCarCollectionTableViewController *carVC = [[ILHomeCarCollectionTableViewController alloc] init];
        [self.navigationController pushViewController:carVC animated:YES];
    }
    
    

    if (indexPath.row == 1) {
        
        ILFavoriteMusicListViewController *musicListVC =[[ILFavoriteMusicListViewController alloc]init];
        [self.navigationController pushViewController:musicListVC animated:YES];
        
    }
    if (indexPath.row==0) {
        
        ILVideoTableViewController *videoVC = [[ILVideoTableViewController alloc]init];
        [self.navigationController pushViewController:videoVC animated:YES];
    }
    
    if (indexPath.row == 5) {
       
        ILAbouOurMessageViewController *oboutUs = [[ILAbouOurMessageViewController alloc]init];
        [self.navigationController pushViewController:oboutUs animated:YES];
        
        
        
    }

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
